package com.nageoffer.shortlink.project.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nageoffer.shortlink.project.dao.entity.LinkStatsTodayDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 短链接今日统计持久层
 */
@Mapper
public interface LinkStatsTodayMapper extends BaseMapper<LinkStatsTodayDO> {

    /**
     * 统计短链接监控今日uv，pv，uip数据
     *
     * @param linkStatsTodayDO
     */
    @Select("""
            insert into t_link_stats_today(full_short_url,date,today_pv,today_uv,today_uip,create_time,update_time,del_flag)
            values(#{linkStatsToday.fullShortUrl},#{linkStatsToday.date},#{linkStatsToday.todayPv},#{linkStatsToday.todayUv},
            #{linkStatsToday.todayUip},now(),now(),0) ON DUPLICATE KEY UPDATE today_pv = today_pv + #{linkStatsToday.todayPv},
            today_uv = today_uv + #{linkStatsToday.todayUv},today_uip = today_uip + #{linkStatsToday.todayUip}, update_time = now()      
            """)
    void shortLinkTodayStats(@Param("linkStatsToday") LinkStatsTodayDO linkStatsTodayDO);
}
